﻿using System.Linq;
using DataScripter.Excel.Formatters;

namespace DataScripter.Excel.Table
{
	class TableExporter
	{
		public string Title { get; set; }
		public TableContent TableContent { get; set; }

		public TableExporter(string title, TableContent table)
		{
			Title = title;
			TableContent = table;
		}

		public void Export(ICell current)
		{
			current.SetAndAdvanceLine(new Title1Formatter(), Title);
			current.SetAndAdvanceLine(new Title2Formatter(), TableContent.Columns.Select(c => c.ColumnText));

			TableContent.StartCell = TableContent.Columns[0].ColumnName == string.Empty
				? current.GetNextColumn(1)
				: current.Clone();
			foreach (TableRow tableRow in TableContent.Rows)
			{
				current.SetAndAdvanceLine(tableRow.Formatter, tableRow.Values);
			}
			current.AdvanceLine();
		}
	}
}
